const articleServer = require("../server/article")
class articleControl {
  async add(req, res) {
    if (!req.file || req.file.fieldname !== "cover_img")
      return res.cc("文章封面是必选参数！")
    const { title, cate_id, content, state } = req.body
    const result = await articleServer.add(
      title,
      cate_id,
      content,
      state,
      req.file.filename,
      req.auth.id
    )
    if (result[0].affectedRows) {
      res.cc("添加成功", 0)
    } else {
      res.cc("添加失败")
    }
  }
}

module.exports = new articleControl()
